home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / hard / drivr / spartan34_4.lha / true_SCSI_version / DirectCmd.asm < prev    next >
Assembly Source File  |  1980-07-31  |  7KB  |  263 lines

  1. ;  
  2. ; SCSIDirectCmd, based on "SCSIRdWt" 
  3. ;
  4. ; Original version by Paul Harker
  5. ; BUSY check on SELECT
  6. ; improved handshake on MSGIN, CMDOUT 
  7. ; 26 May 1992 TM
  8. ; 17 Jun 1992 TM    SCSI BUSY FLAG ADDED for simaltaneous copy bug
  9. ; 15 Sep 1992 TM        GENERIC version
  10. ; 05 Oct 1992 HL        SCSI-Direct version
  11. ;            New selection of unit
  12. ;            Return status when sel. timed out
  13. ;            Return status zero on normal return
  14. ;            Buffers not on 512 b boundaries are treated with
  15. ;              their actual length
  16. ; 22 Oct 1992 HL    Return status bug fixed
  17. ; 25 Oct 1992 HL    Bug introduced above fixed
  18. ;
  19.     include        "exec/types.i"
  20.     include        "exec/io.i"
  21.     include        "exec/devices.i"
  22.     include        "exec/tasks.i"
  23.     include        "exec/interrupts.i
  24.     include        "devices/scsidisk.i"
  25.     include        "mydev.i"
  26.     include        "scsi.i"
  27.  
  28.     Public        SCSIDirectCmd
  29.  
  30. ; In params:
  31. ;    LU in d2
  32. ;     Cmd ptr in a2
  33. ;     Buffer ptr in a0
  34. ;     Buffer length in d0
  35. ;
  36. ; Out params:
  37. ;    IO_Status in d0
  38. ;    SCSI_Status in d7
  39.  
  40. SCSIDirectCmd:
  41.     bset.b    #3,NCR+4    ;TM!!! EOP INTERRUPT bit is used for
  42.     bne.s    SCSIDirectCmd    ;TM!!! SCSI BUSY FLAG
  43.     move.b    #$08,NCR+4    ;TM!!!
  44.     movem.l    d4-d6/a3-a5,-(sp)    ;save regs
  45.     clr.b    d7        ;clear error flag ; HL
  46. STILLbsy1:
  47.     btst.b    #6,NCR+8    ; TM BUSY check
  48.     bne.s    STILLbsy1    ; TM wait if still busy
  49. Drive:
  50.     moveq    #$1,d4
  51.     lsl.l    d2,d4        ;shift to address bit
  52.     or.b    #$80,d4        ;add addresses
  53.     move.b    d4,NCR        ;load addresses
  54.     move.b    #$5,NCR+2    ;assert BUS with address
  55.  
  56. Selection:
  57.     bsr    SELph        ;select the target
  58.  
  59. End:
  60.     bclr.b    #3,NCR+4    ;TM!!! clear SCSI BUSY FLAG
  61.     movem.l    (sp)+,d4-d6/a3-a5    ;restore regs
  62.     rts            ;return to caller
  63.  
  64. SELph:        ;select the target
  65.     move.l  #M250,d5    ;load timer
  66.  
  67. loop1:    btst.b  #6,NCR+8    ;test BSY
  68.     bne.s    SLECT        ;if busy , selected
  69.     subq    #1,d5        ;dec timer
  70.     bne.s    loop1        ;loop
  71.     move.b  #HFERR_SelTimeout,d0 ;set drive not ready error ; HL
  72.     rts
  73.  
  74. SLECT:
  75.     and.b    #$FB,NCR+2    ;clr SEL
  76.       
  77. NextPhase:    ;Check the SCSI bus phase
  78.     move.b    #$0,NCR
  79.     move.b    #$0,NCR+6    ;clear TCR
  80.     btst.b    #5,NCR+8    ;test REQ
  81.     bne.s    GotREQ        ;if REQ it must be busy...
  82.     btst.b    #6,NCR+8    ;check BUSY
  83.     beq    Done        ;bus free
  84.     bra    NextPhase    ; still waiting for REQ
  85. GotREQ:
  86.     btst.b    #3,NCR+8    ;check C/D
  87.     beq.s    Dat        ;data in/out phase
  88.     btst.b    #4,NCR+8    ;check MSG
  89.     bne.s    Message        ;Message in/out phase
  90.     btst.b    #2,NCR+8    ;check I/O
  91.     bne.s    STATph        ;stat phase
  92.     bra.s    CMDph        ;command phase
  93. Message:    ;check to see if it is message in or out
  94.     btst.b    #2,NCR+8    ;check I/O
  95. ;    bne.s    MSGINph      
  96.     bne    MSGINph        ;TM
  97. ;    bra.s    MSGOUTph    ;TM
  98.     bra    MSGOUTph    ;TM        
  99. Dat:        ;check to see if it is data in or out
  100.     btst.b    #2,NCR+8    ;check I/O
  101. ;    bne.s    RDATph
  102.     bne    RDATph        ;TM
  103. ;    bra.s    SDATph        ;TM
  104.     bra    SDATph        ;TM
  105. CMDph:        ;send command
  106.     move.l    a2,a4        ;set the cmd buffer add
  107.     move.b    #$02,NCR+6    ;set TCR to command phase
  108. Send:        ;send x characters to the target
  109.     btst.b    #6,NCR+8    ;TM busy check
  110.     beq    Done        ;TM busy check
  111.     btst.b    #5,NCR+8    ;test for REQ
  112.     beq.s    Send        ;wait for REQ
  113.     btst.b    #3,NCR+10    ;test phase match
  114. ;    beq.s    NextPhase
  115.     beq    NextPhase    ;TM
  116.     move.b    (a4)+,NCR    ;set the byte
  117.     ori.b    #$10,NCR+2    ;set ACK
  118. CMDReq:
  119.     btst.b    #6,NCR+8    ;TM busy check
  120.     beq    Done        ;TM busy check
  121.     btst.b    #5,NCR+8    ; TM test for REQ
  122.     bne.s    CMDReq        ; TM wait for REQ deasserted
  123.     andi.b    #$EF,NCR+2    ;clr ACK
  124.     bra    Send   
  125.  
  126. STATph:        ;get status byte
  127.     move.b    NCR,d7        ;move STATUS into Stat     temp
  128.     ori.b    #$10,NCR+2    ;set ACK
  129. STATReq:
  130.     btst.b    #6,NCR+8    ;TM busy check
  131.     beq    Done        ;TM busy check
  132.     btst.b    #5,NCR+8    ; TM test for REQ
  133.     bne.s    STATReq        ; TM wait for REQ deasserted
  134.     andi.b    #$ef,NCR+2    ;clr ACK
  135.     bra    NextPhase
  136.  
  137. MSGINph:    ;only msg supported is COMPLETE..so we just ack it
  138.     ori.b    #$10,NCR+2    ;set ACK   
  139. MSGINReq:
  140.     btst.b    #6,NCR+8    ;TM busy check
  141.     beq    Done        ;TM busy check
  142.     btst.b    #5,NCR+8    ; TM test for REQ
  143.     bne.s    MSGINReq    ; TM wait for REQ deasserted
  144.     and.b    #$EF,NCR+2    ;clr ACK
  145. STILLbsy:
  146.     btst.b    #6,NCR+8    ; TM BUSY check
  147.     bne.s    STILLbsy    ; TM wait if still busy
  148. Done:        ;did we end normally ?
  149.     move.b    d7,d6
  150.     and.b    #$0e,d6 ; For normal SCSI devices, use this ; HL
  151. ;;;    and.b    #$0c,d6 ; For (older) adaptec cards, use this ; HL
  152.     cmp.b    #$00,d6
  153.     beq    StatOk
  154.     cmp.b    #$04,d6
  155.     beq    StatOk
  156.     move.b    #HFERR_BadStatus,d0
  157.     rts    ;do a clean end
  158. StatOk:
  159.     move.b    #0,d0
  160.     rts    ;do a clean end
  161.  
  162. MSGOUTph:    ;send message to target
  163.     bra    NextPhase    ;error try again
  164.  
  165. SDATph:        ;send data to target
  166.     move.l    a0,a4        ;set the data buffer add
  167.     move.b    #$00,NCR+6    ;set TCR to send data
  168. SendData:    ;send x characters to the target
  169.     btst.b    #6,NCR+8    ;TM busy check
  170.     beq    Done        ;TM busy check
  171.     btst.b    #5,NCR+8    ;test for REQ
  172.     beq.s    SendData    ;wait for REQ
  173.     btst.b    #3,NCR+10    ;test phase match
  174. ;    beq.s    NextPhase
  175.     beq    NextPhase    ;TM
  176. ;    move.b    #$02,NCR+4    ;Set DMAMODE
  177.     bset.b    #1,NCR+4    ;TM!!!
  178.     move.b    #$00,NCR+12    ;start DMA recieve
  179.     move.l  d0,d4
  180.     and.l    #511,d4        ;Check if length is even 512b
  181.     bne    UnevenSend
  182.     moveq    #64,d4        ;load counter..we do 512 byte blocks
  183. LoopTop:
  184.     move.b    (a4)+,DMA    ;set byte 0
  185.     move.b    (a4)+,DMA    ;set byte 1
  186.     move.b    (a4)+,DMA    ;set byte 2
  187.     move.b    (a4)+,DMA    ;set byte 3
  188.     move.b    (a4)+,DMA    ;set byte 4
  189.     move.b    (a4)+,DMA    ;set byte 5
  190.     move.b    (a4)+,DMA    ;set byte 6
  191.     move.b    (a4)+,DMA    ;set byte 7
  192.     subq    #1,d4
  193.     bne.s    LoopTop
  194. SendLast:
  195. ;    move.b    #$0,NCR+4    ;clear DMAMODE
  196.     bclr.b    #1,NCR+4    ;TM!!!
  197.     bra    SendData
  198.  
  199. UnevenSend:
  200.     move.l    d0,d4        ;load counter.. we do bufsize bytes
  201. UnevenSendLoop:            
  202.     move.b    (a4)+,DMA    ;set byte 
  203.     subq    #1,d4        ;decrement counter
  204.     bne.s    UnevenSendLoop    ;done with block?
  205.     bra.s    SendLast
  206.  
  207. RDATph:        ;receive data fron target
  208.     move.l    a0,a4        ;set the data buffer add
  209.     lea    DMA+12,a5    ;set DMA recieve Base
  210.     move.b    #$01,NCR+6    ;set TCR to receive data
  211. RecData:
  212. ;    move.b    #$02,NCR+4    ;Set DMAMODE
  213.     bset.b    #1,NCR+4    ;TM!!!
  214.     move.b    #$00,NCR+14    ;start DMA recieve
  215.     move.l  d0,d4
  216.     and.l    #511,d4        ;Check if length is even 512b
  217.     bne    UnevenRec
  218.     moveq    #63,d4        ;load counter..we do 512 byte blocks
  219. RecLoop:
  220.     move.b    (a5),(a4)+
  221.     move.b    (a5),(a4)+
  222.     move.b    (a5),(a4)+
  223.     move.b    (a5),(a4)+
  224.     move.b    (a5),(a4)+
  225.     move.b    (a5),(a4)+
  226.     move.b    (a5),(a4)+
  227.     move.b    (a5),(a4)+
  228.     subq    #1,d4        ;decrement counter
  229.     bne.s    RecLoop        ;done with block?
  230.     move.b    (a5),(a4)+
  231.     move.b    (a5),(a4)+
  232.     move.b    (a5),(a4)+
  233.     move.b    (a5),(a4)+
  234.     move.b    (a5),(a4)+
  235.     move.b    (a5),(a4)+
  236.     move.b    (a5),(a4)+
  237. RecLast:
  238. ;    move.b    #$0,NCR+4    ;disable ack/req
  239.     bclr.b    #1,NCR+4    ;TM!!!
  240.     move.b    (a5),(a4)+    ;read last byte of block
  241. WRec:
  242.     btst.b    #5,NCR+8    ;test REQ
  243.     bne.s    RReq        ;Got it
  244.     btst.b    #6,NCR+8    ;check BUSY
  245.     beq    Done        ;Not Busy? must be Done.
  246.     bra.s    WRec        ;wait for REQ
  247.  
  248. UnevenRec:
  249.     move.l    d0,d4        ;load counter.. we do bufsize bytes
  250.     subq    #1,d4        ;decrement counter
  251. UnevenRecLoop:            
  252.     move.b    (a5),(a4)+
  253.     subq    #1,d4        ;decrement counter
  254.     bne.s    UnevenRecLoop    ;done with block?
  255.     bra.s    RecLast
  256.  
  257. RReq:
  258.     btst.b    #3,NCR+10    ;test for phase match
  259.     beq    NextPhase
  260.     bra.s    RecData
  261. ;
  262.     END
  263.